<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Legacy  Reference</title>
    <link rel="stylesheet" type="text/css" href="css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="css/highlight.css" />
    <meta charset='utf-8'>
    <script src="js/jquery.min.js" defer></script>
    <script src="js/jazzy.js" defer></script>
    
    <script src="js/lunr.min.js" defer></script>
    <script src="js/typeahead.jquery.js" defer></script>
    <script src="js/jazzy.search.js" defer></script>
  </head>
  <body>
    <a title="Legacy  Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="index.html">SwiftyMocky 4.2.0 Docs</a> (86% documented)</p>
        <p class="header-right"><a href="https://github.com/MakeAWishFoundation/SwiftyMocky"><img src="img/gh.png" alt="GitHub"/>View on GitHub</a></p>
        <div class="header-right">
          <form role="search" action="search.json">
            <input type="text" placeholder="Search documentation" data-typeahead>
          </form>
        </div>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="index.html">SwiftyMocky Reference</a>
        <img id="carat" src="img/carat.png" alt=""/>
        Legacy  Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="Main%20Guides.html">Main Guides</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="overview.html">Overview</a>
              </li>
              <li class="nav-group-task">
                <a href="installation.html">Installation</a>
              </li>
              <li class="nav-group-task">
                <a href="setup-in-project.html">Setup in project</a>
              </li>
              <li class="nav-group-task">
                <a href="mockfile.html">Mockfile</a>
              </li>
              <li class="nav-group-task">
                <a href="command-line-interface.html">Command Line Interface</a>
              </li>
              <li class="nav-group-task">
                <a href="supported-features.html">Supported features</a>
              </li>
              <li class="nav-group-task">
                <a href="prototyping.html">Prototyping</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Additional%20Guides.html">Additional Guides</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="matcher-support-for-not-equatable.html">Matcher support for not Equatable</a>
              </li>
              <li class="nav-group-task">
                <a href="handling-generics.html">Handling Generics</a>
              </li>
              <li class="nav-group-task">
                <a href="examples.html">Examples</a>
              </li>
              <li class="nav-group-task">
                <a href="legacy.html">Legacy</a>
              </li>
              <li class="nav-group-task">
                <a href="add-xcode-generate-action.html">Add XCode generate action</a>
              </li>
              <li class="nav-group-task">
                <a href="known-issues.html">Known issues</a>
              </li>
              <li class="nav-group-task">
                <a href="changelog.html">CHANGELOG</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Global%20methods.html">Global methods</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Global%20methods.html#/s:11SwiftyMocky5Givenyyx_ABQzAA14StubbingPolicyOtAA4MockRzlF">Given(_:_:_:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Global%20methods.html#/s:11SwiftyMocky5Givenyyxm_06StaticC0QzAA14StubbingPolicyOtAA0D4MockRzlF">Given(_:_:_:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Global%20methods.html#/s:11SwiftyMocky7Performyyx_ABQztAA4MockRzlF">Perform(_:_:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Global%20methods.html#/s:11SwiftyMocky7Performyyxm_06StaticC0QztAA0D4MockRzlF">Perform(_:_:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Global%20methods.html#/s:11SwiftyMocky6Verify__4file4lineyx_ABQzs12StaticStringVSutAA4MockRzlF">Verify(_:_:file:line:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Global%20methods.html#/s:11SwiftyMocky6Verify__4file4lineyxm_06StaticC0Qzs0F6StringVSutAA0F4MockRzlF">Verify(_:_:file:line:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Global%20methods.html#/s:11SwiftyMocky6Verify___4file4lineyx_AA5CountOABQzs12StaticStringVSutAA4MockRzlF">Verify(_:_:_:file:line:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Global%20methods.html#/s:11SwiftyMocky6Verify___4file4lineyxm_AA5CountO06StaticC0Qzs0G6StringVSutAA0G4MockRzlF">Verify(_:_:_:file:line:)</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Configuration.html">Configuration</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Enums/StubbingPolicy.html">StubbingPolicy</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/SequencingPolicy.html">SequencingPolicy</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Types.html">Types</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Protocols/Mock.html">Mock</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/StaticMock.html">StaticMock</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/Parameter.html">Parameter</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/Matcher.html">Matcher</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/Matcher/ComparisonResult.html">– ComparisonResult</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/Matcher/ParameterComparisonResult.html">– ParameterComparisonResult</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/Countable.html">Countable</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/Count.html">Count</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/Stubber.html">Stubber</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/StubberThrows.html">StubberThrows</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Generics.html">Generics</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Structs/GenericAttribute.html">GenericAttribute</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Helpers.html">Helpers</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Helpers.html#/s:11SwiftyMocky20XCTAssertThrowsError_2of_4file4lineyxyKXK_q_mSSyXKs12StaticStringVSuts0E0R_r0_lF">XCTAssertThrowsError(_:of:_:file:line:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Helpers.html#/s:11SwiftyMocky20XCTAssertThrowsError_5error_4file4lineyxyKXK_q_SSyXKs12StaticStringVSutSQR_s0E0R_r0_lF">XCTAssertThrowsError(_:error:_:file:line:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/MockyAssertion.html">MockyAssertion</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Internal.html">Internal</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Classes/SwiftyMockyTestObserver.html">SwiftyMockyTestObserver</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/SwiftyMockyTestObserver.html">SwiftyMockyTestObserver</a>
              </li>
              <li class="nav-group-task">
                <a href="Structs/FatalErrorUtil.html">FatalErrorUtil</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/OptionalType.html">OptionalType</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/WithSequencingPolicy.html">WithSequencingPolicy</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/WithStaticSequencingPolicy.html">WithStaticSequencingPolicy</a>
              </li>
              <li class="nav-group-task">
                <a href="Protocols/WithStubbingPolicy.html">WithStubbingPolicy</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/Int.html">Int</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/Optional.html">Optional</a>
              </li>
              <li class="nav-group-task">
                <a href="Extensions/UInt.html">UInt</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/MockError.html">MockError</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/StubProduct.html">StubProduct</a>
              </li>
              <li class="nav-group-task">
                <a href="Classes/StubbedMethod.html">StubbedMethod</a>
              </li>
              <li class="nav-group-task">
                <a href="Internal.html#/s:11SwiftyMocky7Failureys5NeverOSSF">Failure(_:)</a>
              </li>
              <li class="nav-group-task">
                <a href="Internal.html#/s:11SwiftyMocky0B6Assert__4file4lineySbyXK_SSyXKs12StaticStringVSutF">MockyAssert(_:_:file:line:)</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Other%20Guides.html">Other Guides</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="contents.html">Contents</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Other%20Classes.html">Other Classes</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Classes/ArgumentCaptor.html">ArgumentCaptor</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Other%20Enums.html">Other Enumerations</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Enums/MockScope.html">MockScope</a>
              </li>
              <li class="nav-group-task">
                <a href="Enums/Utils.html">Utils</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Other%20Protocols.html">Other Protocols</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Protocols/TypeErasedValue.html">TypeErasedValue</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="Other%20Structs.html">Other Structures</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="Structs/TypeErasedAttribute.html">TypeErasedAttribute</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            
            <h1 id='legacy' class='heading'>Legacy</h1>

<p>If really you don&rsquo;t want to use the <strong>CLI</strong> (😢) then you can still use SwiftyMocky with a Sourcery configuration, described below. This is the &ldquo;old&rdquo; way of integrating our library.</p>

<p>Summing up, you need <strong>SwiftyMocky</strong> framework in the runtime, and <strong>sourcery</strong> binary with a configuration pointing to our template for the mocks generation.</p>
<h2 id='installation' class='heading'>Installation</h2>

<p>SwiftyMocky is available through <a href="http://cocoapods.org">CocoaPods</a>. To install it, simply add the following line to your Podfile:</p>
<pre class="highlight ruby"><code><span class="n">pod</span> <span class="s2">"SwiftyMocky"</span>
</code></pre>

<p>Then add <strong>mocky.yml</strong> and <strong>Rakefile</strong> (or build script phase) to your project root directory, as described in below. See full [setup][link-docs-setup] instructions.</p>

<p>For <a href="https://github.com/Carthage/Carthage">Carthage</a> install instructions, see full [documentation][link-docs-installation].</p>
<h3 id='generating-mocks-implementations' class='heading'>Generating mocks implementations:</h3>

<p>One of the boilerplate part of testing and development is writing and updating <strong>mocks</strong> accordingly to newest changes. SwiftyMocky is capable of generating mock implementations (with configurable behavior), based on protocol definition.</p>

<p>During development process it is possible to use SwiftyMocky in a <em>watcher</em> mode, which will observe changes in you project files, and regenerate files on the fly.</p>

<p><img src="https://raw.githubusercontent.com/MakeAWishFoundation/SwiftyMocky/1.0.0/guides/assets/example-watcher.gif" alt="Generating mock" title="Example - generation"></p>

<p>By default, all protocols marked as AutoMockable (inheriting from dummy protocol <code>AutoMockable</code> or annotated with <code>//sourcery: AutoMockable</code>) are being subject of mock implementation generation. All mocks goes to <code>Mock.generated.swift</code>, which can be imported into test target.</p>
<h1 id='how-to-start-using-swiftymocky' class='heading'>How to start using SwiftyMocky</h1>

<p>Mocks generation is based on <code>mocky.yml</code> file.</p>

<p>First, create file in your project root directory with following structure:</p>
<pre class="highlight yaml"><code><span class="na">sources</span><span class="pi">:</span>
  <span class="na">include</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">./ExampleApp</span>
    <span class="pi">-</span> <span class="s">./ExampleAppTests</span>
<span class="na">templates</span><span class="pi">:</span>
  <span class="pi">-</span> <span class="s">./Pods/SwiftyMocky/Sources/SwiftyMocky</span>
<span class="na">output</span><span class="pi">:</span>
  <span class="s">./ExampleApp</span>
<span class="na">args</span><span class="pi">:</span>
  <span class="na">testable</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">ExampleApp</span>
  <span class="na">import</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">RxSwift</span>
    <span class="pi">-</span> <span class="s">RxBlocking</span>
  <span class="na">excludedSwiftLintRules</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">force_cast</span>
    <span class="pi">-</span> <span class="s">function_body_length</span>
    <span class="pi">-</span> <span class="s">line_length</span>
    <span class="pi">-</span> <span class="s">vertical_whitespace</span>
</code></pre>

<ul>
<li><strong>sources</strong>: all directories you want to scan for protocols/files marked to be auto mocked, or inline mocked. You can use <code>exclude</code>, to prevent from scanning particular files (makes sense for big <code>*.generated.swift</code> files)</li>
<li><strong>templates</strong>: path to SwiftyMocky sourcery templates, in Pods directory</li>
<li><strong>output</strong>: place where <code>Mock.generated.swift</code> will be placed</li>
<li><strong>testable</strong>: specify imports for Mock.generated, that should be marked as <code>@testable</code> (usually tested app module)</li>
<li><strong>import</strong>: all additional imports, external libraries etc. to be placed in Mock.generated</li>
<li><strong>excludedSwiftLintRules</strong>: if using swift SwiftLint.</li>
</ul>

<p>If you are already using <a href="https://github.com/krzysztofzablocki/Sourcery">Sourcery</a> with your own templates and you have configured <code>sourcery.yml</code> file, you can extend it to add support for SwiftyMocky. Click [here][link-guides-installation] for details.</p>
<h2 id='generate-mocks' class='heading'>Generate mocks:</h2>

<ol>
<li><strong>manually</strong>: by triggering:</li>
</ol>

<p><code>Pods/Sourcery/bin/sourcery --config mocky.yml</code></p>

<ol>
<li><strong>in <code>watch</code> mode</strong>: changed methods will be reflected in mocks, after generation of mock, by triggering:</li>
</ol>

<p><code>Pods/Sourcery/bin/sourcery --config mocky.yml --watch</code></p>

<blockquote>
<p><strong>!!! In case of incompatibile swift module versions error</strong> - check Known issues section in guides or docs</p>
</blockquote>

<p><strong>Don&rsquo;t forget</strong> to add <code>Mock.generated.swift</code> to your test target :)</p>

<blockquote>
<p><strong>Please Note!</strong>
Most convenient way is to put generation in some kind of script - like Rakefile below.
Just create file named Rakefile - generation is triggered by <code>rake mock</code></p>
<pre class="highlight ruby"><code><span class="c1"># Rakefile</span>
<span class="n">task</span> <span class="ss">:mock</span> <span class="k">do</span>
  <span class="n">sh</span> <span class="s2">"Pods/Sourcery/bin/sourcery --config mocky.yml"</span>
<span class="k">end</span>

<span class="n">task</span> <span class="ss">:mock_watcher</span> <span class="k">do</span>
  <span class="n">sh</span> <span class="s2">"Pods/Sourcery/bin/sourcery --config mocky.yml --watch"</span>
<span class="k">end</span>
</code></pre>
</blockquote>
<h2 id='setup-for-sourcery-users-alternative-to-mocky-yml' class='heading'>Setup for Sourcery users (alternative to mocky.yml):</h2>

<p>We know that Sourcery is a powerful tool and you are likely to use it already. You can easily integrate SwiftyMocky with your project with keeping all already written templates working.</p>

<p>All you have to do is add path (note that path can be different for Carthage/manual installation) to SwiftyMocky templates in your <code>sourcery.yml</code> file:</p>
<pre class="highlight yaml"><code><span class="na">sources</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">./ExampleApp</span>
    <span class="pi">-</span> <span class="s">./ExampleAppTests</span>
<span class="na">templates</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">&lt;templates path&gt;</span> <span class="c1"># Path to already written Sourcery templates</span>
    <span class="pi">-</span> <span class="s">./Pods/SwiftyMocky/Sources/SwiftyMocky</span> <span class="c1"># &lt;- SwiftyMocky templates</span>
<span class="na">output</span><span class="pi">:</span>
    <span class="s">./ExampleApp</span>
<span class="na">args</span><span class="pi">:</span>
  <span class="na">testable</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">ExampleApp</span>
  <span class="na">import</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">RxSwift</span>
    <span class="pi">-</span> <span class="s">RxBlocking</span>
  <span class="na">excludedSwiftLintRules</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="s">force_cast</span>
    <span class="pi">-</span> <span class="s">function_body_length</span>
    <span class="pi">-</span> <span class="s">line_length</span>
    <span class="pi">-</span> <span class="s">vertical_whitespace</span>
</code></pre>

<p>You can use all arguments (like <code>testable</code>, <code>import</code>, etc.) in the same way as in <code>mocky.yaml</code>, under <code>args</code> key.</p>
<h2 id='strong-get_sourcery-sh-strong' class='heading'><strong>get_sourcery.sh</strong></h2>

<p>This is a helper script allowing to obtain Sourcery binary compiled for usage with SwiftyMocky. It can be used with both: legacy configurations and new Mockfile (specify path to binary in Mockfile <code>sourceyCommand</code>)</p>
<pre class="highlight shell"><code><span class="o">[[</span> <span class="nv">$# </span>&gt; 0 <span class="o">]]</span> <span class="o">&amp;&amp;</span> <span class="nv">VERSION</span><span class="o">=</span><span class="s2">"</span><span class="nv">$1</span><span class="s2">"</span> <span class="o">||</span> <span class="nv">VERSION</span><span class="o">=</span><span class="s2">"5.0"</span>
<span class="o">[[</span> <span class="nv">$# </span>&gt; 1 <span class="o">]]</span> <span class="o">&amp;&amp;</span> <span class="nv">OUTPUT</span><span class="o">=</span><span class="s2">"</span><span class="nv">$2</span><span class="s2">"</span> <span class="o">||</span> <span class="nv">OUTPUT</span><span class="o">=</span><span class="s2">"./Pods/Sourcery/bin"</span>
<span class="nv">SOURCERY_VERSION</span><span class="o">=</span><span class="s2">"0.16.0"</span> <span class="c"># The version of Sourcery that is associated with this SwiftyMocky version</span>

<span class="nb">echo</span> <span class="s2">"CLONE SOURCERY </span><span class="nv">$SOURCERY_VERSION</span><span class="s2"> FOR Swift </span><span class="nv">$VERSION</span><span class="s2"> INTO </span><span class="nv">$OUTPUT</span><span class="s2">"</span>
rm -r -f <span class="s2">"</span><span class="nv">$OUTPUT</span><span class="s2">"</span>
git clone -b <span class="s2">"sourcery/</span><span class="nv">$SOURCERY_VERSION</span><span class="s2">-swift</span><span class="nv">$VERSION</span><span class="s2">"</span> --single-branch --depth 1 https://github.com/MakeAWishFoundation/SwiftyMocky.wiki.git <span class="s2">"</span><span class="nv">$OUTPUT</span><span class="s2">"</span>
</code></pre>

<blockquote>
<p><strong>Note!</strong>
This script is also shipped with SwiftyMocky when installing via cocoapods
You can use it from project root like <code>sh ./Pods/SwiftyMocky/get_sourcery.sh 4.2</code>
Version is optional, if you don&rsquo;t specify it, script will use latest supported (5.0 in that case)</p>

<p><strong>Note 2!</strong>
If you use Carthage, you should specify your custom output location for sourcery binary. Please have in mind, that script clears output dir, so don&rsquo;t point it to <code>~/</code> or something ;)</p>
</blockquote>

<!-- Assets -->

          </section>
        </section>
        <section id="footer">
          <p>Copyright © 2017 MakeAWishFoundation. All rights reserved.</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external noopener">jazzy ♪♫ v0.14.2</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external noopener">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</html>
